package com.zcy.nidavellir.multilogin

import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.zcy.nidavellir.multilogin.login.LoginFactory
import com.zcy.nidavellir.multilogin.proxy.LOGINTYPE
import kotlinx.android.synthetic.main.activity_main.*
import java.lang.ref.WeakReference

class MainActivity : AppCompatActivity() {

    private fun action() {
        LoginFactory.createLoginImpl(WeakReference(this), type).action()
    }

    private var type = LOGINTYPE.WECHAT
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        wechat.setOnClickListener {
            type = LOGINTYPE.WECHAT
            action()
        }
        phone.setOnClickListener {
            type = LOGINTYPE.PHONE
            action()
        }
        twitter.setOnClickListener {
            type = LOGINTYPE.TWITTER
            action()
        }
        facebook.setOnClickListener {
            type = LOGINTYPE.FACEBOOK
            action()
        }
        google.setOnClickListener {
            type = LOGINTYPE.GOOGLE
            action()
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        LoginFactory.currentLoginImpl.onActivityResult(requestCode, resultCode, data)
    }
}
